
import * as express from "express";

let cookieParser = require('cookie-parser');
let moment = require('moment-timezone');
moment.defaultFormat = "YYYY-MM-DD HH:mm:ss";

let app = express();
app.set('view engine', 'ejs')
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());

import { loginRouter, tokens } from "./routes/login";
import { roleRoute } from "./routes/role";
import { noticeRoute } from "./routes/notice";
import { serverRoute } from './routes/server';
import { mailRoute } from "./routes/mail";
import { itemRoute } from "./routes/item";
import { captainRoute } from "./routes/captain";
import { maidRoute } from "./routes/maid";
import { onlineRoute } from "./routes/online";
import { questRoute } from "./routes/quest";

app.use("/login", loginRouter);

app.use("/", function (req, res, next) {
    if (!req.cookies.token || !tokens[req.cookies.token]) {

        res.redirect("/login");
    } else {
        next()
    }
})

captainRoute(app);
roleRoute(app);
noticeRoute(app);
serverRoute(app);
maidRoute(app);
mailRoute(app);
itemRoute(app);
onlineRoute(app);
questRoute(app);

app.get('/', function (req, res) {
    res.render('index');
})

app.listen(8000, () => console.log('Server listening on port 8000!'))
